package wjh.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import wjh.pojo.ExamForm;
import wjh.pojo.ReportUserDoctor;

import java.util.List;

@Repository
public interface ZlyExamFormMapper {

    @Insert("insert into reports values (null, #{user_name}, #{report_number}, #{date}, #{department}, #{result}, #{status})")
    void saveForm(ExamForm examForm);

    @Insert("insert into report_orders values (#{rNumber}, #{money})")
    void saveOrder(@Param("rNumber") String report_number, @Param("money") int money);

    @Insert("insert into report_user_doctor values (null, #{rNumber}, #{pid}, #{did})")
    void saveExamtoDoct(@Param("rNumber") String reportNumber, @Param("pid") Integer pid, @Param("did") Integer did);

    @Update("UPDATE reports SET status = #{status} WHERE report_number = #{rNumber}")
    void changeState(@Param("rNumber") String reportNumber, @Param("status") int status);

    @Select("select * from report_user_doctor where doctor_id = #{value} limit 1")
    ReportUserDoctor findReportUserDoctorByDid(Integer did);

    @Select("select * from reports where report_number = #{value}")
    ExamForm findByReportNumber(String reportNumber);

    @Update("update reports set results = concat(results, '\r\n', #{subExam}) where report_number = #{rNumber}")
    void subExam(@Param("subExam") String subExam, @Param("rNumber") String rNumber);

    @Delete("delete from report_user_doctor where report_number = #{rNumber} and doctor_id = #{did}")
    void delRUD(@Param("rNumber") String rNumber, @Param("did") int did);

    @Select("SELECT COUNT(* ) AS num FROM report_user_doctor WHERE report_number = #{value} GROUP BY report_number")
    Object checkReportDone(String rNumber);

    @Select("select * from reports where user_name = #{value} and status != -2")
    List<ExamForm> findByPname(String pname);
}
